﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using DLM.Infrastructure.Domain;

namespace DLM.Domain.Model
{
    public class Invitation : IValidatableObject, IAggregateRoot
    {
        public int InvitationID { get; set; }

        [Required(ErrorMessage = "请选择正确的用户")]
        [RegularExpression(@"^[0-9]*$", ErrorMessage = "请输入正确的用户编号！")]
        public int UserID { get; set; }

        [Required(ErrorMessage = "请选择正确的活动")]
        [RegularExpression(@"^[0-9]*$", ErrorMessage = "请输入正确的活动编号！")]
        public int PartyID { get; set; }

        public bool IsConfirmed { get; set; }

        [Required(ErrorMessage = "请选择正确的用户")]
        [RegularExpression(@"^[0-9]*$", ErrorMessage = "请输入正确的邀请者编号！")]
        public int SenderID { get; set; }

        [Required(ErrorMessage = "账户不允许为空")]
        [RegularExpression(@"^[a-zA-Z][a-zA-Z0-9_]{4,20}$", ErrorMessage = "昵称允许数字，字母和下划线")]
        public string SenderAccount { get; set; }
        public System.DateTime InviteDate { get; set; }

        public virtual User User { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (UserID < 0)
            {
                yield return new ValidationResult("请确认要邀请的用户！");
            }
            if (PartyID < 0)
            {
                yield return new ValidationResult("请确认要邀请参加的活动！");
            }
        }
    }
}
